package ygg.encoding.swf.tag.codec
{
	import flash.utils.ByteArray;
	import j.sus2maj7.encoding.*;
	import j.sus2maj7.context.*;
	import j.sus2maj7.util.ByteUtil;
	
	import ygg.encoding.swf.tag.*;
	import ygg.encoding.swf.tag.object.*;
	
	public class DoActionCodec extends TagCodec
	{
		public function DoActionCodec()
		{
			super();
		}
		
		override public function decode(binary:IBinary, context:IContext=null):*
		{
			var retVal:DoAction = new DoAction();
			var b:TagBinary = binary as TagBinary;
			b.position = 0;
			b.syncBits();
			
			trace('do action', ByteUtil.print(b.ba) );
			//array of actionrecord until 0
			var actionCode:uint;
			var len:uint;
			actionCode = b.readU8();
			retVal.actionRecords = [];
			
			while ( actionCode != 0)
			{
				if (actionCode >= 0x80)
					len = b.readU16();
				else len = 0;
				var b2:ByteArray = new ByteArray();
				b.readBytes(b2, 0, len);
				
				retVal.actionRecords.push( { code: actionCode, length: len, b: b2} );
				trace( 'code', actionCode, 'length', len);
				
				
				actionCode = b.readU8();
			}
			
			
			
			//action record -> code ui8 length ui16
			
			return retVal;
		}
		
		override public function encode(o:*, context:IContext=null):IBinary
		{
			var b:TagBinary = new TagBinary();
			var obj:DoAction = o as DoAction;
			
			
			
			return b;
		}
	}
}